package com.tianruan.dc.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @PS
 */

@Configuration
public class ExecutorConfig {
    @Bean("contractProcessExector")
    public ThreadPoolTaskExecutor contractProcessExector() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        int i = Runtime.getRuntime().availableProcessors();//获取到服务器的cpu内核
        executor.setCorePoolSize(1);//核心池大小
        executor.setMaxPoolSize(10);//最大线程数
        executor.setQueueCapacity(5000);//队列程度
        executor.setKeepAliveSeconds(300);//线程空闲时间
        executor.setThreadNamePrefix("tsak-asyn");//线程前缀名称
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());//配置拒绝策略
        return executor;
    }
}